package com.hibernate.learn2.models;

import javax.persistence.*;

@Entity
@Table(name = "Person")
public class Person extends MappedSuper {

    public Person() {}

    public Person(String name) {
        this.name = name;
    }

    public Person(String name, Passport passport) {
        this.name = name;
        this.passport = passport;
    }

    @Column(name = "username")
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToOne(cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name = "pass_id")
    private Passport passport;

    public Passport getPassport() {
        return passport;
    }

    public void setPassport(Passport passport) {
        this.passport = passport;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", passport=" + passport.getSerial() +
                '}';
    }
}
